package com.cjst.service.impl.sys;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cjst.dao.mapper.sys.SysRelationMapper;
import com.cjst.pojo.sys.SysRelation;
import com.cjst.service.impl.base.BaseServiceImpl;
import com.cjst.service.sys.SysRelationService;
import com.cjst.sql.C;
import com.cjst.sql.Method;
import com.cjst.sql.WherePrams;
/**
 * 部门服务
 * @author yj
 *
 */
@Service
public class SysRelationServiceImpl extends BaseServiceImpl<SysRelation, String> implements SysRelationService{

	
	@Autowired
	private SysRelationMapper relationMapper;
	
	@Override
	@Transactional
	public void setAuthority(String roleId, String ids) {
		// TODO Auto-generated method stub
		//删除改角色拥有的权限
		WherePrams wherePrams = Method.where("roleid", C.EQ, roleId);
		this.del(wherePrams);
		//为该角色新增权限
		if(StringUtils.isNotEmpty(ids)){
			String[] arr = ids.split(",");
			for (String id : arr) {
				SysRelation relation = new SysRelation();
				relation.setMenuid(id);
				relation.setRoleid(roleId);
				this.addLocalByid(relation);
				
			}
		}
		//redisService.setObj(CommonConstant.SESSION_ROLE_AUTH, null);
		
	}

	
	
	@Override
	public List<Map<String, Object>> getRoleIds(String roleid) {
		// TODO Auto-generated method stub
		List<Map<String, Object>> maps = relationMapper.getRoleIds(roleid);
		return maps;
	}

	
}
